package com.cys.dm.rest.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cys.dm.dao.base.DmImageDao;
import com.cys.dm.entity.base.DmImage;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class DmImageSrevice {
    @Resource
    private DmImageDao dmImageDao;

    @PostMapping(path = "/slideshow")
    public List<DmImage> slideshow(){
        QueryWrapper<DmImage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type",1L);
        return dmImageDao.selectList(queryWrapper);
    }

    @PostMapping(path = "/findItenPicByID")
    public DmImage findItenPicByID(@RequestBody Long targetId) {
        QueryWrapper<DmImage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("targetId",targetId);
        DmImage dmImage = dmImageDao.selectOne(queryWrapper);
        if (dmImage == null){
            dmImage = new DmImage();
            dmImage.setImgUrl("/static/img/cardimg3.jpg");
        }
        return dmImage;
    }

    @PostMapping(path = "/findUserPicByIDAndType")
    public DmImage findUserPicByIDAndType(@RequestParam Long targetId,@RequestParam Long type) {
        QueryWrapper<DmImage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("targetId",targetId);
        queryWrapper.eq("type",type);
        DmImage dmImage = dmImageDao.selectOne(queryWrapper);
        if (dmImage == null){
            dmImage = new DmImage();
            dmImage.setImgUrl("/static/img/cardimg3.jpg");
        }
        return dmImage;
    }

    /**
     * 根据图片类型图片分类查询对应图片
     * @param targetId 节目ID
     * @param type 图片类型
     * @param category 图片分类
     * @return
     */
    @PostMapping("findImage/{targetId}/{type}/{category}")
    public List<DmImage> findImage(
            @PathVariable("targetId")Long targetId,
            @PathVariable("type")Long type,
            @PathVariable("category")Long category
    ){
        QueryWrapper<DmImage> query = new QueryWrapper<>();
        query.eq("targetId",targetId);
        query.eq("type",type);
        query.eq("category",category);
        return dmImageDao.selectList(query);
    }

}
